#include "fxcc/core/graph/common/AnimationNode.h"

using namespace fxcc::graph::common;

void AnimationNode::Tick(float deltaTime)
{
	if (!m_AnimationMap.m_Value)
	{
		return;
	}

	m_AnimAxis += deltaTime / m_AnimationMap.m_Value->m_TotalTime * m_AdditionConfig.m_AnimSpeed;

	if (m_AnimAxis > 0.99f)
	{
		m_ReachEnd = true;
	}

	if (m_AdditionConfig.m_Looping)
	{
		if (m_AnimAxis > 0.99f)
		{
			m_AnimAxis = 0.01f;
		}
		if (m_AnimAxis < 0.01f)
		{
			m_AnimAxis = 0.99f;
		}
	}

}

void AnimationNode::UpdateBoneData()
{
	if (!m_AnimationMap.m_Value)
	{
		return;
	}

	m_AnimationMap.m_Value->UpdateChannelsWithAxis(m_AnimAxis);

}

bool AnimationNode::SetAnimNode(const std::string& nodeName, fxcc::graph::common::AnimNode* animNode)
{
	auto anim = GetAnimation();
	if (!anim)
	{
		return false;
	}
	return anim->SetAnimNode(nodeName, animNode);

}

